package ve.usb.ddp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import ve.usb.cohesion.runtime.CohesionAction;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import ve.usb.cohesion.runtime.HibernateUtil;
import ve.usb.ddp.hibernate.*;


/**
 * Manejo de elementos de la entidad PaiRemuneracion.<br>
 */
public class AccionesPaiRemuneracion extends CohesionAction {
    
/**
     * Called by Struts for the execution of action APreBuscar_paiRemuneracion.
     * Prepara la vista de selección de criterios de búsqueda para una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreBuscar_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VBuscar_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiRemuneracionBuscar.clear(mapping, request);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APreCrear_paiRemuneracion.
     * Prepara la vista de captura de datos de una entidad para realizar una inserción.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreCrear_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VCrear_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiRemuneracion fFPaiRemuneracion = FPaiRemuneracion.clear(mapping, request);

             //Feed for combo listPaiResolucion.
             {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
                (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
                "select new ve.usb.cohesion.runtime.Pair(fec_Resolucion, idResolucion) " + 
                "from PaiResolucion").list();
              list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
              fFPaiRemuneracion.setListPaiResolucion(list);
             }


            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action ABuscar_paiRemuneracion.
     * Captura los criterios de búsqueda y los fija en la sesión.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward ABuscar_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"APreListar_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiRemuneracionBuscar fFPaiRemuneracionBuscar = (FPaiRemuneracionBuscar)form;
            request.getSession().setAttribute("ABuscar_paiRemuneracion_campo", "concepto");
            request.getSession().setAttribute("ABuscar_paiRemuneracion_valor", "%" + fFPaiRemuneracionBuscar.getConcepto() + "%");

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APreListar_paiRemuneracion.
     * Selecciona las entidades a ser listadas de acuerdo a los parámetros recibidos.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreListar_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VListar_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            String crit = (String)request.getSession().getAttribute("ABuscar_paiRemuneracion_campo");
            java.util.List<PaiRemuneracion> list;
            if (crit==null) {
                list = (java.util.List<PaiRemuneracion>)s.createQuery("from PaiRemuneracion").list();
            } else {
                String valor = (String)request.getSession().getAttribute("ABuscar_paiRemuneracion_valor");
                list = (java.util.List<PaiRemuneracion>)
                   s.createQuery("from PaiRemuneracion where "+crit+" like :valor")
                    .setString("valor", valor).list();
                request.getSession().removeAttribute("ABuscar_paiRemuneracion_campo");
                request.getSession().removeAttribute("ABuscar_paiRemuneracion_valor");
            }
            request.setAttribute("L_PaiRemuneracion", list);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APre_paiRemuneracion.
     * Prepara la vista de actualización de una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APre_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            Long idRemuneracion = lookup_Long(request, "idRemuneracion");
            
            FPaiRemuneracion fFPaiRemuneracion = FPaiRemuneracion.clear(mapping, request);
            PaiRemuneracion paiRemuneracion = (PaiRemuneracion)s.load(PaiRemuneracion.class, idRemuneracion);
            fFPaiRemuneracion.setIdRemuneracion(paiRemuneracion.getIdRemuneracion());

            fFPaiRemuneracion.setResolucion(paiRemuneracion.getResolucion().getIdResolucion());

            fFPaiRemuneracion.setConcepto(paiRemuneracion.getConcepto());
            fFPaiRemuneracion.setTipo_Financiamiento(paiRemuneracion.getTipo_Financiamiento());
            fFPaiRemuneracion.setFec_Ini(paiRemuneracion.getFec_Ini().toString());
            fFPaiRemuneracion.setFec_Fin(paiRemuneracion.getFec_Fin().toString());

            //Feed for combo listPaiResolucion.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(fec_Resolucion, idResolucion) " + 
               "from PaiResolucion").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiRemuneracion.setListPaiResolucion(list);
            }

            for (PaiPago _PaiPago : paiRemuneracion.getSet_Pago()) {
                Hibernate.initialize(_PaiPago.getRemuneracion());
            }
            request.setAttribute("L_PaiPago", paiRemuneracion.getSet_Pago());


            request.getSession().setAttribute("idResolucion_super", fFPaiRemuneracion.getResolucion());

            request.getSession().setAttribute("idRemuneracion", idRemuneracion);
            request.getSession().setAttribute("idRemuneracion_super", idRemuneracion);

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action AAct_paiRemuneracion.
     * Registro de actualizaciones de una entidad.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward AAct_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiRemuneracion fFPaiRemuneracion = (FPaiRemuneracion)form;
            PaiRemuneracion paiRemuneracion = (PaiRemuneracion)s.load(PaiRemuneracion.class, fFPaiRemuneracion.getIdRemuneracion());
            paiRemuneracion.setConcepto(fFPaiRemuneracion.getConcepto());
            paiRemuneracion.setTipo_Financiamiento(fFPaiRemuneracion.getTipo_Financiamiento());
            paiRemuneracion.setFec_Ini(new ve.usb.cohesion.runtime.LocalDate(fFPaiRemuneracion.getFec_Ini()));
            paiRemuneracion.setFec_Fin(new ve.usb.cohesion.runtime.LocalDate(fFPaiRemuneracion.getFec_Fin()));


            //Feed for combo listPaiResolucion.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(fec_Resolucion, idResolucion) " + 
               "from PaiResolucion").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiRemuneracion.setListPaiResolucion(list);
            }

            for (PaiPago _PaiPago : paiRemuneracion.getSet_Pago()) {
                Hibernate.initialize(_PaiPago.getRemuneracion());
            }
            request.setAttribute("L_PaiPago", paiRemuneracion.getSet_Pago());

            request.getSession().setAttribute("idRemuneracion", paiRemuneracion.getIdRemuneracion());
            request.getSession().setAttribute("idRemuneracion_super", paiRemuneracion.getIdRemuneracion());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("AAct_paiRemuneracion.msg0"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action AElim_paiRemuneracion.
     * Elimina la entidad seleccionada.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward AElim_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"APreListar_paiRemuneracion", "V_paiRemuneracion", };
        final int SALIDA_0 = 0;
        final int SALIDA_1 = 1;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            Long idRemuneracion = lookup_Long(request, "idRemuneracion");
            PaiRemuneracion paiRemuneracion = (PaiRemuneracion)s.load(PaiRemuneracion.class, idRemuneracion);
            s.delete(paiRemuneracion);
            try {
                s.flush();
            } catch (Exception ex1) {
                ex1.printStackTrace();
                salida = SALIDA_1;
            }

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("AElim_paiRemuneracion.msg0"));
        }
        if (salida==1) {
          request.setAttribute("msg",
            getResources(request).getMessage("AElim_paiRemuneracion.msg1"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action ACrear_paiRemuneracion.
     * Registro de la creación de una PaiRemuneracion.<br>
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward ACrear_paiRemuneracion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"V_paiRemuneracion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiRemuneracion fFPaiRemuneracion = (FPaiRemuneracion)form;
            PaiRemuneracion paiRemuneracion = new PaiRemuneracion();
            paiRemuneracion.setConcepto(fFPaiRemuneracion.getConcepto());
            paiRemuneracion.setTipo_Financiamiento(fFPaiRemuneracion.getTipo_Financiamiento());
            paiRemuneracion.setFec_Ini(new ve.usb.cohesion.runtime.LocalDate(fFPaiRemuneracion.getFec_Ini()));
            paiRemuneracion.setFec_Fin(new ve.usb.cohesion.runtime.LocalDate(fFPaiRemuneracion.getFec_Fin()));

            s.save(paiRemuneracion);
            s.flush();
            fFPaiRemuneracion.setIdRemuneracion(paiRemuneracion.getIdRemuneracion());

            //Feed for combo listPaiResolucion.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(fec_Resolucion, idResolucion) " + 
               "from PaiResolucion").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiRemuneracion.setListPaiResolucion(list);
            }

            request.getSession().setAttribute("idRemuneracion", paiRemuneracion.getIdRemuneracion());
            request.getSession().setAttribute("idRemuneracion_super", paiRemuneracion.getIdRemuneracion());

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        if (salida==0) {
          request.setAttribute("msg",
            getResources(request).getMessage("ACrear_paiRemuneracion.msg0"));
        }

        return mapping.findForward(SALIDAS[salida]);
    }

/**
     * Called by Struts for the execution of action APreCrear_paiRemuneracion_paiResolucion.
     * Prepara la vista de captura de datos de una entidad para realizar una inserción.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @return The Struts name of the following step.
     * @throws java.lang.Exception For untreated exceptions. 
     * These exceptios will normally be treated with 
     * the default exception action.
     */
    public ActionForward APreCrear_paiRemuneracion_paiResolucion(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        //Salidas
        final String[] SALIDAS = {"VCrear_paiRemuneracion_paiResolucion", };
        final int SALIDA_0 = 0;

        int salida = SALIDA_0;
//Checking for actors administrador
            if (!CohesionActor.checkActor(request, 1)) {
                return mapping.findForward(CohesionActor.SALIDA_ACTOR);
            }
        Session s = HibernateUtil.getCurrentSession();
        Transaction tr = s.beginTransaction();
        try {
            FPaiRemuneracion fFPaiRemuneracion = FPaiRemuneracion.clear(mapping, request);

            //Feed for combo listPaiResolucion.
            {java.util.List<ve.usb.cohesion.runtime.Pair> list = 
               (java.util.List<ve.usb.cohesion.runtime.Pair>)s.createQuery(
               "select new ve.usb.cohesion.runtime.Pair(fec_Resolucion, idResolucion) " + 
               "from PaiResolucion").list();
             list.add(0,new ve.usb.cohesion.runtime.Pair("Ninguna", 0));
             fFPaiRemuneracion.setListPaiResolucion(list);
            }

            fFPaiRemuneracion.setResolucion(Long.parseLong((String)request.getParameter("idResolucion_super")));

            tr.commit();

        } catch (Exception ex) {
            tr.rollback();
            throw ex;
        } finally {
            try { s.close(); } catch (Exception ex2) {}
        }
        return mapping.findForward(SALIDAS[salida]);
    }



}